package com.donica.wamstest.Controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.donica.wamstest.entity.CommonFindVO;
import com.donica.wamstest.entity.LogVO;
import com.donica.wamstest.entity.ReturnMessage;
import com.donica.wamstest.service.LogService;

import io.swagger.annotations.Api;


/*
 * @author chris
 * @version 1.0
 * @date  2020/4/14 15:12
 * @description 用户控制器
 */
@RestController
@RequestMapping("/api/v1/")
@Api(value = "logController", tags = "日志控制器")
public class LogController {
	
	@Autowired
    private LogService logService;
	
    // 添加用户
 	@RequestMapping(value = "logs", method = RequestMethod.POST)
 	public ReturnMessage InsertLog(@RequestBody List<LogVO> volist) {
 		ReturnMessage rtnMsg = new ReturnMessage();
 		try {

 			long count = logService.InsertLog(volist);
 			rtnMsg.setResult(count);
 		} catch (Exception e) {
 			rtnMsg.setCode(ReturnMessage.FAIL);
 			rtnMsg.setMsg(e.getMessage());
 		}

 		return rtnMsg;
 	}

 
 	@RequestMapping(value = "logs", method = RequestMethod.DELETE)
 	public ReturnMessage DeleteLog(@RequestBody List<LogVO> volist) {
 		ReturnMessage rtnMsg = new ReturnMessage();
 		try {

 			long count = logService.deleteLog(volist);
 			rtnMsg.setResult(count);
 		} catch (Exception e) {
 			rtnMsg.setCode(ReturnMessage.FAIL);
 			rtnMsg.setMsg(e.getMessage());
 		}

 		return rtnMsg;
 	}

 	@RequestMapping(value = "logs/list/{pageSize}/{currPage}", method = RequestMethod.POST)
 	public ReturnMessage searchLog(@PathVariable("pageSize") int pageSize, @PathVariable("currPage") int currPage,
 			@RequestBody CommonFindVO vo) {
 		int firstIndex = pageSize * currPage;
 		vo.setFirstIndex(firstIndex);
 		vo.setPageSize(pageSize);
 		vo.setCurrPage(currPage);
 		return logService.searchLog(vo);
 	}

}
